local InnerDataDefine = require("innerdata.Define")
local InnerDataManager = require("innerdata.InnerDataManagerFL")
local ObjHuman = require("core.ObjHuman")
local Util = require("common.Util")
local FirstPayLogic = require("fuli.FirstPayLogic")
local VipLogic = require("vip.VipLogic")
local RoleDefine = require("role.RoleDefine")
local ChongzhiRebate = require("activity.operate.ChongzhiRebate")
local ChongzhiPresent = require("activity.operate.ChongzhiPresent")
local ChongzhiDateRebate = require("activity.date.ChongzhiRebate")

function pay(human, type, data)
    ObjHuman.updateDaily(human)

    local oldYB = human.db.historyYuanbao
    ObjHuman.addYuanbao(human, data.yb, "pay")
    InnerDataManager.Send2WInnerData(human, InnerDataDefine.INNERDATA_TYPE_PAY_L, data)
    local oldPay = human.db.rmb
    human.db.rmb = human.db.rmb + data.rmb

    if oldPay == 0 then
        human.db.firstPay = 1
        human.db.everyDayPay = 100
        FirstPayLogic.query(human, 1)
        FirstPayLogic.openFirstPayPanel(human)
    elseif human.db.everyDayPay < 100 then
        human.db.everyDayPay = human.db.everyDayPay + data.yb
        if human.db.everyDayPay >= 100 and Util.getBit(human.db.firstPay, 1) == 0 then
            human.db.firstPay = human.db.firstPay + 2
            FirstPayLogic.query(human, 2)
        end
    end
    human.db.lastPayTime = os.time()
    ObjHuman.doCalc(human)
    --充值后回调
    
    human.db.historyYuanbao = human.db.historyYuanbao + data.yb   -- 累计充值元宝    
    human.db.dailyChongzhi = human.db.dailyChongzhi + data.yb --每日累计充值    
    human.attr[RoleDefine.HISTORY_CHONGZHI] = human.db.historyYuanbao
    human.attr[RoleDefine.DAILY_CHONGZHI] = human.db.dailyChongzhi    
    ChongzhiRebate.checkCanGet(human)
    ChongzhiDateRebate.checkCanGet(human)
    ChongzhiPresent.query(human)
    VipLogic.setRewardCanGet(human, oldYB)
    ObjHuman.sendAttr(human, RoleDefine.HISTORY_CHONGZHI)
    ObjHuman.sendAttr(human, RoleDefine.DAILY_CHONGZHI) 
end
InnerDataManager.Register(InnerDataDefine.INNERDATA_TYPE_PAY_W,  pay)
